package com.pptree.dao.impl;

import java.sql.SQLException;
import java.util.Date;

import com.pptree.dao.UserDAO;
import com.pptree.util.BaseDAO;
import com.pptree.vo.User;

public class UserDAOImpl extends BaseDAO implements UserDAO {

	@Override
	public User findUserByUsername(String uname) {
		String sql = "select * from users where username=?";
		User user = null;
		
		rs = executeQuery(sql, uname);
		
		try {
			if(rs.next()){
				int id = rs.getInt("id");
				String username = rs.getString("username");
				String password = rs.getString("password");
				String email = rs.getString("email");
				int userType = rs.getInt("usertype");
				String realName = rs.getString("realname");
				Date regDate = rs.getDate("regdate");
				user = new User(id, username, password, email, userType, realName, regDate);
			}
			
		} 
		catch (SQLException e) {
			e.printStackTrace();
		}finally{
			closeAll(rs, pstmt, conn);
		}
		return user;
	}

}
